﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using HtmlAgilityPack;
using PMC.Scripts;
using PMC.Structs;
using PMC.Urls;
using System.Threading.Tasks;

namespace PMC.Interfaces
{
    public delegate void webpageChanged(Website website, Uri visited);

    public delegate void browserStateChanged(BrowserState newState);

    /// <summary>
    /// Interface that every browser-wrapper must implement
    /// </summary>
    public interface IWbrowser
    {
        /// <summary>
        /// Interval of the webbrowser for visiting new pages
        /// </summary>
        int TimerInterval { get; set; }
        /// <summary>
        /// DateTime the webbrowser visited the last document
        /// </summary>
        DateTime TimerElapse { get; }
        /// <summary>
        /// Current website that associated with the webpage
        /// <remarks>This will be <b>null</b> if no match was found!</remarks>
        /// </summary>
        Website CurrentWebsite { get; }
        /// <summary>
        /// State the webbrowser currently is in
        /// </summary>
        BrowserState State { get; }
        /// <summary>
        /// Current document displayed in browser
        /// </summary>
        HtmlDocument Document { get; }
        /// <summary>
        /// Source of the current document
        /// </summary>
        String DocumentText { get; }
        /// <summary>
        /// Current Url displayed in the browser
        /// </summary>
        Uri Url { get; }

        /// <summary>
        /// Navigates to the next url in the list
        /// Throws:
        /// ConnectionException | No internetconnection available
        /// InvalidOperatoinException | Empty queue
        /// </summary>
        void Next();
        /// <summary>
        /// Navigates to the next url in the list
        /// Throws:
        /// ConnectionException | No internetconnection available
        /// InvalidOperatoinException | Empty queue
        /// </summary>
        Task NextAsync();
        /// <summary>
        /// Start browser navigation
        /// </summary>
        void Start();
        /// <summary>
        /// Start browser navigation
        /// </summary>
        Task StartAsync();
        /// <summary>
        /// Stops borwser navigation
        /// </summary>
        void Stop();
        /// <summary>
        /// Setting a internal cookie to the browser
        /// </summary>
        /// <param name="url">Url where the cookie applies to</param>
        /// <param name="cookie">The cookie(collection)</param>
        void SetCookie(Uri url, CookieCollection cookie);
        /// <summary>
        /// Returns all the cookies that exists for the given url
        /// </summary>
        /// <param name="url">Domain to search for</param>
        /// <returns>Collection of cookies</returns>
        CookieCollection GetCookies(Uri url);
        /// <summary>
        /// Returns all cookies for the current url
        /// </summary>
        /// <returns>Collection of cookies</returns>
        CookieCollection GetCookies();

        event webpageChanged WebpageVisited;
        void OnWebpageVisited();
        event browserStateChanged BrowserStateChanged;
        void OnBrowserStateChanged();
    }
}
